<?php
/**
 * Soar Framework - Lightweight and simple to use PHP Framework
 *
 * Soar is free software and is distributed WITHOUT ANY WARRANTY
 *
 * @package Soar
 * @version 1.0 $Id: SoarConfNode.php 2 2012-04-06 21:50:33Z shay@shayanderson.com $
 * @copyright Copyright (c) 2012 ShayAnderson.com
 * @license http://www.gnu.org/licenses/gpl.html GPL License
 * @link http://www.shayanderson.com/projects/soar-php-framework.htm
 */

/**
 * Soar Framework Configuration Node Class
 * 
 * @package Soar
 * @name SoarConfNode
 * @author Shay Anderson 03.12
 */
final class SoarConfNode
{
	/**
	 * Node path, ex: 'core->debug'
	 * 
	 * @var string 
	 */
	private $__path;
	
	/**
	 * Config settings
	 * 
	 * @var array 
	 */
	public $conf = array();
	
	/**
	 * Init
	 * 
	 * @param string $path 
	 */
	public function __construct($path)
	{
		$this->__path = $path;
	}
	
	/**
	 * Config setting value getter
	 * 
	 * @param string $key
	 * @return mixed
	 */
	public function __get($key)
	{
		if(!$this->__isset($key))
		{
			trigger_error("Failed to load configuration setting \"{$this->__path}->{$key}\""
				. ', does not exist', SoarErrorHandler::ERROR);
		}
		return $this->conf[$key];
	}
	
	/**
	 * Check if config setting exists
	 * 
	 * @param string $key
	 * @return bool
	 */
	public function __isset($key)
	{
		return isset($this->conf[$key]);
	}
	
	/**
	 * Config setting value setter
	 * 
	 * @param string $key
	 * @param mixed $value
	 * @return void
	 */
	public function __set($key, $value)
	{
		$this->conf[$key] = $value;
	}
	
	/**
	 * Node path getter
	 * 
	 * @return string 
	 */
	public function getPath()
	{
		return $this->__path;
	}
}
?>